package vip.huhaiong.hlfood.service.impl;

import org.jsoup.nodes.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import vip.huhaiong.hlfood.pojo.Rs;
import vip.huhaiong.hlfood.service.FoodHeatService;
import vip.huhaiong.hlfood.utils.JsoupUtil;
import vip.huhaiong.hlfood.utils.RsUtil;

import java.util.List;
import java.util.Map;

/**
 * @program: hlfood
 * @description: 食物热量接口实现类
 * @author: 胡海龙
 * @create: 2021-07-09 21:56:12
 **/
@Service
public class FoodHeatServiceImpl implements FoodHeatService {
    JsoupUtil jsoupUtil;

    @Autowired
    public FoodHeatServiceImpl(JsoupUtil jsoupUtil){
        this.jsoupUtil = jsoupUtil;
    }


    @Override
    public Rs searchFoodHeat(String foodName) throws Exception {
        String url = "http://www.boohee.com/food/search?keyword="+foodName;
        Document htmlString;
        htmlString = jsoupUtil.getHtmlString(url);
        List<Map<String, Object>> foodHeatList = jsoupUtil.getFoodHeatList(htmlString);
        return RsUtil.success("查询成功",foodHeatList);

    }

    @Override
    public Rs searchFoodHeatDetail(String detailUrl) throws Exception {
        List<Map<String, Object>> foodHeatDetail = jsoupUtil.getFoodHeatDetail(detailUrl);
        return RsUtil.success("查询成功",foodHeatDetail);
    }
}
